package com.jiu.bean;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import com.jiu.core.FishClient;

public class SendMessageThread extends Thread{
	private int a=0,b=0,c=0,d=0,e=0;
	private FishClient context;
	public SendMessageThread(FishClient context){
		this.context = context;
		this.setName("SendMessageThread-Thread");
	}
	@Override
	public void run() {
		SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss"); 
		while(true){
			try {Thread.sleep(new Random().nextInt(3500)+500);} catch (InterruptedException e1) {}
			int check = 1;
			if(context.getSendMap().size()>0){
				check = context.getSendMap().get(1)!=null?1:check;
				check = context.getSendMap().get(2)!=null?2:check;
				check = context.getSendMap().get(3)!=null?3:check;
				check = context.getSendMap().get(4)!=null?4:check;
				check = context.getSendMap().get(5)!=null?5:check;
				if(check==1)a++;
				else if(check==2)b++;
				else if(check==3)c++;
				else if(check==4)d++;
				else if(check==5)e++;
				//发消息
				String sendMsg =context.getSendMap()==null?"":context.getSendMap().get(check).trim();
				context.getFishHttpService().sendFishMsg(sendMsg);
				//将信息更新到面板
				context.displayMessage(context.getAccount().getNickname()+"："+sendMsg+"      统计：钓鱼（"+(a+c)+"）;卖鱼（"+b+"）;新指令（"+c+"）;其他（"+d+"）;控制（"+e+"）　" + fmt.format(new Date()),Color.RED);
				//普通命令，清除某次命令
				context.getSendMap().remove(check);	
				if(check==5)context.getSendMap().remove(2);
			}
			context.getMainFrame().updateStackMessage(context.getSendMap());
			try {
				Thread.sleep(context.getAccount().getTime()*1000);
			} catch (InterruptedException ex) {	}
			//当无消息处理时，停止指定时间、秒
			
		}//外层while结束
	}
	public int getA() {
		return a;
	}
	public int getB() {
		return b;
	}
	public int getC() {
		return c;
	}
	public int getD() {
		return d;
	}
	public int getE() {
		return e;
	}
	
}
